package com.xueyi.aixihu.constant;

import com.xueyi.aixihu.config.SpringContextConfig;
import com.xueyi.aixihu.entity.generatedMapper.DtNewsMapper;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @author 俞烨
 * @version 1.0
 * @description: 审核的区域枚举
 * @date 2023/12/10 21:15
 */

@AllArgsConstructor
@Getter
public enum SystemRoleAuditAreaEnum {

    Z_DJB_CY(SystemRoleConstant.Z_DJB_CY, "镇党建办成员", Collections.singletonList(AddressConstant.CUN), Arrays.asList( 7,9,10,11,12,33, 28, 29, 30, 31, 32),SystemRoleConstant.Z_DJB_ZR),
    Z_DJB_ZR(SystemRoleConstant.Z_DJB_ZR, "镇党建办主任", Arrays.asList(AddressConstant.CUN, AddressConstant.ZJ), Arrays.asList(7, 9, 10, 11, 12, 28, 29, 30, 31, 32, 33),SystemRoleConstant.Z_DJB_ZR),
    Z_XG_BM(SystemRoleConstant.Z_XG_BM, "镇相关部门", Arrays.asList(AddressConstant.CUN, AddressConstant.SQ), new ArrayList<>(),-1),
    Z_BM_FW_ZX_ZR(SystemRoleConstant.Z_BM_FW_ZX_ZR, "镇便民服务中心主任", Arrays.asList(AddressConstant.CUN, AddressConstant.SQ, AddressConstant.ZJ), new ArrayList<>(),-1),
    Z_CZS_CY(SystemRoleConstant.Z_CZS_CY, "镇财政所成员", Arrays.asList(AddressConstant.SQ, AddressConstant.JW), new ArrayList<>(),SystemRoleConstant.Z_CZS_SZ),
    Z_CZS_SZ(SystemRoleConstant.Z_CZS_SZ, "镇财政所所长", Arrays.asList(AddressConstant.JW, AddressConstant.SQ, AddressConstant.ZJ), new ArrayList<>(),SystemRoleConstant.Z_CZS_SZ),
    CUN(SystemRoleConstant.CUN, "村", new ArrayList<>(), new ArrayList<>(),-1),
    SQ(SystemRoleConstant.SQ, "社区", new ArrayList<>(), new ArrayList<>(),-1),
    JWH(SystemRoleConstant.JU_WEI, "居委会", new ArrayList<>(), new ArrayList<>(),-1),
    Z_JGZ_CY(SystemRoleConstant.Z_JGZ_CY, "镇经管站成员", Collections.singletonList(AddressConstant.CUN), Arrays.asList(35, 14, 33, 34, 13,16, 36),SystemRoleConstant.Z_JGZ_ZZ),
    Z_JGZ_ZZ(SystemRoleConstant.Z_JGZ_ZZ, "镇经管站站长", Collections.singletonList(AddressConstant.CUN), Arrays.asList(35, 14, 33, 34, 13,16, 36),SystemRoleConstant.Z_JGZ_ZZ),
    JW(SystemRoleConstant.JW, "纪委", new ArrayList<>(), new ArrayList<>(),-1),
    XG_ZN_GM(SystemRoleConstant.XG_ZN_GM, "相关职能部门", new ArrayList<>(), new ArrayList<>(),-1),

    Z_MZB_CY(SystemRoleConstant.Z_MZB_CY, "镇民政办成员", new ArrayList<>(), Arrays.asList(21, 22, 23, 24, 25, 26, 41, 42, 43, 44, 45, 46, 14),SystemRoleConstant.Z_MZB_ZR),
    Z_NF_A_ZB_CY(SystemRoleConstant.Z_NF_A_ZB_CY, "镇农房安置办成员", new ArrayList<>(), Arrays.asList(20, 40),SystemRoleConstant.Z_NF_A_ZB_ZR),
    Z_GG_ZY_JY_ZX_CY(SystemRoleConstant.Z_GG_ZY_JY_ZX_CY, "镇公共资源交易中心成员", new ArrayList<>(), Arrays.asList(19, 39),SystemRoleConstant.Z_GG_ZY_JY_ZX_ZR),
    Z_ZS_XM_B_CY(SystemRoleConstant.Z_ZS_XM_B_CY, "镇征收项目办成员", new ArrayList<>(), Arrays.asList(17, 18, 37, 38),SystemRoleConstant.Z_ZS_XM_B_ZR),
    Z_NY_FW_ZX_CY(SystemRoleConstant.Z_NY_FW_ZX_CY, "镇农业服务中心成员", new ArrayList<>(), Arrays.asList(35, 14),SystemRoleConstant.Z_NY_FW_ZX_ZR),
    Z_LB_S_CY(SystemRoleConstant.Z_LB_S_CY, "镇劳保所成员", new ArrayList<>(), Arrays.asList(15),SystemRoleConstant.Z_LB_S_ZR),

    Z_MZB_ZR(SystemRoleConstant.Z_MZB_ZR, "镇民政办主任", new ArrayList<>(), Arrays.asList(21, 22, 23, 24, 25, 26, 41, 42, 43, 44, 45, 46, 14),SystemRoleConstant.Z_MZB_ZR),
    Z_NF_A_ZB_ZR(SystemRoleConstant.Z_NF_A_ZB_ZR, "镇农房安置办主任", new ArrayList<>(), Arrays.asList(20, 40),SystemRoleConstant.Z_NF_A_ZB_ZR),
    Z_GG_ZY_JY_ZX_ZR(SystemRoleConstant.Z_GG_ZY_JY_ZX_ZR, "镇公共资源交易中心主任", new ArrayList<>(), Arrays.asList(19, 39),SystemRoleConstant.Z_GG_ZY_JY_ZX_ZR),
    Z_ZS_XM_B_ZR(SystemRoleConstant.Z_ZS_XM_B_ZR, "镇征收项目办主任", new ArrayList<>(), Arrays.asList(17, 18, 37, 38),SystemRoleConstant.Z_ZS_XM_B_ZR),
    Z_NY_FW_ZX_ZR(SystemRoleConstant.Z_NY_FW_ZX_ZR, "镇农业服务中心主任", new ArrayList<>(), Arrays.asList(35, 14),SystemRoleConstant.Z_NY_FW_ZX_ZR),
    Z_LB_S_ZR(SystemRoleConstant.Z_LB_S_ZR, "镇劳保所主任", new ArrayList<>(), Arrays.asList(15),SystemRoleConstant.Z_LB_S_ZR);

    public Integer ROLE_ID;
    public String ROLE_NAME;
    public List<Integer> AUDIT_TYPE;
    public List<Integer> MANAGE_AUDIT_SYSTEM_TYPE_ID;
    public Integer NEXT_AUDIT_ROLE_ID;

    public static String getSystemTypeAuditName(Integer systemId, List<Integer> roleList) {

        List<String> auditRoleNames=new ArrayList<>();
        StringJoiner stringJoiner = new StringJoiner("/");
        for (SystemRoleAuditAreaEnum systemRoleAuditAreaEnum : SystemRoleAuditAreaEnum.values()) {
            String roleName=systemRoleAuditAreaEnum.getROLE_NAME();
            if(roleName.indexOf("主任")!=-1||roleName.indexOf("成员")!=-1||roleName.indexOf("站长")!=-1){
                roleName=roleName.substring(0,roleName.length()-2);
            }
            if(systemRoleAuditAreaEnum.MANAGE_AUDIT_SYSTEM_TYPE_ID.contains(systemId)&&!auditRoleNames.contains(roleName)){
                if (!CollectionUtils.isEmpty(roleList)) {
                    if(roleList.contains(systemRoleAuditAreaEnum.ROLE_ID)){
                        stringJoiner.add(roleName);
                        auditRoleNames.add(roleName);
                    }
                } else {
                    stringJoiner.add(roleName);
                    auditRoleNames.add(roleName);
                }
            }
        }
        return stringJoiner.toString();
    }

    public static SystemRoleAuditAreaEnum getInstance(Integer roleId) {
        for (SystemRoleAuditAreaEnum systemRoleAuditAreaEnum : SystemRoleAuditAreaEnum.values()) {
            if (systemRoleAuditAreaEnum.getROLE_ID().equals(roleId)) {
                return systemRoleAuditAreaEnum;
            }
        }
        return null;
    }
}

